package cn.fay.chapter14;

import java.util.ArrayList;

public class Staff extends ArrayList<Position> {
	public void add(String title, NPerson person) {
		add(new Position(title, person));
	}
	public void add(String... titles) {
		for (String title : titles) {
			add(new Position(title));
		}
	}
	public Staff(String...titles) {
		add(titles);
	}
	public boolean positionAvailable(String title) {
		for (Position position : this) {
			if (position.getTitle().equals(title)&&position.getnPerson()==NPerson.NULL) {
				return true;
			}
		}
		return false;
	}
	public void fillPosition(String title,NPerson hire) {
		for (Position position : this) {
			if (position.getTitle().equals(title)&&position.getnPerson()==NPerson.NULL) {
				position.setnPerson(hire);
				return;
			}
		}
		throw new RuntimeException("Position "+title+" not available");
	}
	
	public static void main(String[] args) {
		Staff staff=new Staff("President","CTO","Marketing Manager","Product Manager","Project Leader",
				"Software Engineer","Software Engineer","Software Engineer","Software Engineer",
				"Test Engineer","Technical Writer");
		staff.fillPosition("President", new NPerson("Me", "Last", "The Top,Lonely At"));
		staff.fillPosition("Project Leader", new NPerson("Janet", "Planner", "The Burbs"));
		if (staff.positionAvailable("Software Engineer")) {
			staff.fillPosition("Software Engineer", new NPerson("Bob", "Coder", "Bright Light City"));
		}
		System.out.println(staff);
	}
}
